﻿using JX.Core;
using JX.Core.Entity;
using JX.Infrastructure.Common;
using JX.Infrastructure.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace JX.Application
{
	/// <summary>
	/// 数据库表：CommonInfo 的应用层服务接口实现类.
	/// </summary>
	public partial class CommonInfoServiceAppDapper : ICommonInfoServiceAppDapper
	{
		#region 虚节点内容列表
		/// <summary>
		/// 获取指定generalId的内容信息对应的虚节点内容列表（LinkType = 1）
		/// </summary>
		/// <param name="generalId"></param>
		/// <returns></returns>
		public IEnumerable<CommonInfoEntity> GetInfoList(int generalId) 
		{
			IEnumerable<CommonInfoEntity> list = new List<CommonInfoEntity>();
			var commonModelInfoById = Get(generalId);
			if (commonModelInfoById != null)
			{
				list = GetList(p => p.LinkType == 1 && p.ItemID == commonModelInfoById.GeneralID && p.TableName == commonModelInfoById.TableName);
			}
			return list;
		}
		/// <summary>
		/// 获取指定generalId的内容信息对应的虚节点内容列表（LinkType = 1）
		/// </summary>
		/// <param name="generalId"></param>
		/// <returns></returns>
		public async Task<IEnumerable<CommonInfoEntity>> GetInfoListAsync(int generalId)
		{
			IEnumerable<CommonInfoEntity> list = new List<CommonInfoEntity>();
			var commonModelInfoById = Get(generalId);
			if (commonModelInfoById != null)
			{
				list = await GetListAsync(p => p.LinkType == 1 && p.ItemID == commonModelInfoById.GeneralID && p.TableName == commonModelInfoById.TableName);
			}
			return list;
		}
		#endregion
	}
}